package com.anzia.list;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

/**
 *@ClassName Collection1_Demo
 *@Description
 *@Author Anzia.
 *@Date 2021/4/10 9:40
 *@Version 1.0
 **/
public class Collection1_Demo {
    public static void main(String[] args) {
        //新建对象
        Collection collection = new ArrayList();
        Student student1 = new Student("张三", 20);
        Student student2 = new Student("李四", 22);
        Student student3 = new Student("王五", 21);

        //添加数据
        collection.add(student1);
        collection.add(student2);
        collection.add(student3);

        System.out.println("集合个数：" + collection.size());
        System.out.println(collection.toString());

        //删除
        //list.remove(student1);
        //list.clear();
        //System.out.println("删除之后：" + list);

        //遍历
        //增强for
        System.out.println("------------");
        for (Object o : collection) {
            Student s = (Student) o;
            System.out.println(s);
        }

        //迭代器
        System.out.println("------------");
        Iterator iterator = collection.iterator();
        while (iterator.hasNext()) {
            Student next = (Student) iterator.next();
            System.out.println(next);
        }

        //判断
        System.out.println("------------");
        System.out.println(collection.contains(student1));
        System.out.println(collection.isEmpty());
    }
}
